package com.jingdianjichi.wx.handler;

import com.jingdianjichi.wx.enums.WxChatMsgTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 关注的处理器
 */
@Component
@Slf4j
public class SubscribeMsgHandler implements WxChatMsgHandler{
    @Override
    public WxChatMsgTypeEnum getMsgType() {
        return WxChatMsgTypeEnum.SUBSCRIBE;
    }

    @Override
    public String dealMsg(Map<String, String> messageMap) {
        log.info("触发用户关注事件");

        String toUserName = messageMap.get("ToUserName");          //发给谁的,公众号
        String fromUserName = messageMap.get("FromUserName");      //谁发的.微信用户

        //恢复的消息
        String subscribeContent="你好,我是经典鸡翅,欢迎学习!!";

        String replyContent="<xml>\n" +
                "  <ToUserName><![CDATA["+fromUserName+"]]></ToUserName>\n" +
                "  <FromUserName><![CDATA["+toUserName+"]]></FromUserName>\n" +
                "  <CreateTime>12345678</CreateTime>\n" +
                "  <MsgType><![CDATA[text]]></MsgType>\n" +
                "  <Content><![CDATA["+subscribeContent+"]]></Content>\n" +
                "</xml>";

        return replyContent;
    }
}
